<?php
// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.filesystem.folder');

class TableUserPim extends JTable {
    var $id = null;
    var $name = null;
    var $username = null;
    var $email = null;
    var $password = null;
    var $usertype = null;
    var $block = null;
    var $sendEmail = null;
    var $registerDate = null;
    var $lastvisitDate = null;
    var $lastvisitDate = null;
    var $activation = null;
    var $params = null;
    var $lastResetTime = null;
    var $resetCount = null;
    
    
    
       

    function __construct( &$_db ) {
        parent::__construct( '#__product', 'id', $_db );
    }
    
	function deleteAll($aid, $where = '') {
        JArrayHelper::toInteger($aid);
        
        foreach ($aid AS $id) {
			$this->load($id);
        }
     
        if(!is_array($aid) ) {
            $aid = array(intval($aid));
        }
            
        $query = 'DELETE FROM ' . $this->_db->nameQuote($this->_tbl) .
            	' WHERE ' . $this->_tbl_key . ' IN (' . implode(',', $aid) . ')' .
        		((!empty($where)) ? $where : '');

        $this->_db->setQuery($query);
        if ($this->_db->query()) {
            return true;
        } else {
            $this->setError($this->_db->getErrorMsg());
            return false;
        }
    }
    
    function saveRecord($data) {
    	if (empty($data['id'])) {
			$Config = JModel::getInstance('Config', 'ManagerModel');
        	$ObjConfig = $Config->getConfigByKey("duration_expired");
        	$num_expired_value = intval($ObjConfig->pim_value);
        
        	$today = date("Y-m-d H:i:s",mktime(0, 0, 0, date("m"), date("d"), date("Y")));
        	$expired_num = date("Y-m-d H:i:s",mktime(0, 0, 0, date("m"), date("d")+$num_expired_value, date("Y")));
        
        	$data['sale_date'] = $today;
        	$data['expired_date'] = $expired_num;
		}

		$this->save($data);
    }
    
}